package com.ABdolphin.forum.controller;

import com.ABdolphin.forum.common.AppResult;
import com.ABdolphin.forum.exception.ApplicationException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name="测试接口")
@RestController
@RequestMapping("/test")
public class TestController {
    @Operation(summary = "测试接口1,打印hello")
    @GetMapping("hello")
    public String hello(){
        return "hello";
    }
    @Operation(summary = "测试接口2,测试统一异常返回exception")
    @GetMapping("/exception")
    public void exception() throws Exception {
        throw new Exception("这是exception一个异常信息");
    }
    @Operation(summary = "测试接口3,测试统一异常返回AppException")
    @GetMapping("/applicationException")
    public void applicationException() throws ApplicationException {
        throw new ApplicationException("这是一个applicationException异常信息");
    }
    @Operation(summary = "测试接口4,输入名字,返回你好")
    @PostMapping("/helloByName")
    public AppResult<String> helloByName(@Parameter(name = "name", description = "用户姓名") String name)  {
        return AppResult.success("你好: "+name);
    }

}
